/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.util.ArrayList;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import physics.Physics;

/**
 *
 * @author wida46061976
 */
public class Bullet implements Entity {

    private boolean player;
    private float posX = 0;
    private float posY = 0;
    private float velX = 0;
    private float velY = 0;
    private Polygon poly;
    private ArrayList<Image> imgs;
    public Animation animation;
    public boolean lost=false;

    public boolean isLost() {
        return lost;
    }

    public void setLost(boolean lost) {
        this.lost = lost;
    }

    public Bullet(float posX, float posY, boolean player, boolean left) {
        init(posX, posY, player, left);
    }
    private void init(float posX, float posY, boolean player, boolean left){
        this.posY=posY;
        this.player = player;
        if (left) {
            this.velX=-4f;
            this.posX=posX+20;
        } else {
            this.velX=4f;
            this.posX=posX+65;
        }
        animation=new Animation();
        animation.setAutoUpdate(false);
        poly=new Polygon(new float[]{0, 0, 8, 0, 8, 6, 0, 6});
        poly.setX(this.posX);
        poly.setY(this.posY);
        try {
        animation.addFrame(new Image("resources/bala.png"), 1000);
        } catch (SlickException e) {
            System.out.println(e);
        }
    }

    public float getPosX() {
        return posX;
    }

    public float getPosY() {
        return posY;
    }

    public void setPosX(float posX) {
        this.posX = posX;
    }

    public void setPosY(float posY) {
        this.posY = posY;
    }

    public float getVelX() {
        return velX;
    }

    public float getVelY() {
        return velY;
    }

    public void setVelX(float velX) {
        this.velX = velX;
    }

    public void setVelY(float velY) {
        this.velY = velY;
    }

    public Polygon getPoly() {
        return poly;
    }

    public boolean isPlayer() {
        return player;
    }

    public void setPlayer(boolean player) {
        this.player = player;
    }

    public void setPoly(float xLeft, float xRight, float yUp, float yBottom) {
        this.poly = new Polygon(new float[]{xLeft, yUp, xRight, yUp, xRight, yBottom, xLeft, yBottom});
    }

    public ArrayList<Image> getImgs() {
        return imgs;
    }

    public void setImgs(ArrayList<Image> imgs) {
        this.imgs = imgs;
    }

    public Animation getAnimation() {
        return animation;
    }

    public void setAnimation(Animation animation) {
        this.animation = animation;
    }

    public void Update(GameContainer gc, int delta, Physics phys) {
        posX = posX + phys.bulletdist(velX, delta, poly, posX, this);
        poly.setX(posX);
    }

    public void Render(GameContainer gc, Graphics g, int incX, int incY) {
        g.drawAnimation(animation, posX + incX, posY + incY);
        //g.draw(poly);
    }
}
